package com.kanche.bigbaby.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kanche.bigbaby.R;
import com.kanche.bigbaby.bean.LoginUser;
import com.kanche.bigbaby.support.utils.ViewUtility;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chenshao_Young on 15/5/19.
 */
public class SmListViewAdapter extends BaseAdapter {

    List<LoginUser> mList = new ArrayList<>();
    Context context;

    public SmListViewAdapter(Context context,List<LoginUser> mList) {
        this.mList = mList;
        this.context = context;
    }

    /**
     * 此处需要重写
     * @param position
     * @return
     */

    @Override
    public int getItemViewType(int position) {
        return position%2;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh ;
        if(convertView == null){
            convertView = View.inflate(context,R.layout.adapter_smlistview,null);
            vh = new ViewHolder();
            vh.iv_car = ViewUtility.findViewById(convertView,R.id.iv_car);
            vh.title = ViewUtility.findViewById(convertView,R.id.title);
            vh.price = ViewUtility.findViewById(convertView,R.id.price);
            vh.date = ViewUtility.findViewById(convertView,R.id.date);
            vh.address = ViewUtility.findViewById(convertView,R.id.address);
            vh.time = ViewUtility.findViewById(convertView,R.id.time);

            convertView.setTag(vh);

        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.address.setText("帝都");

        return convertView;
    }

    class ViewHolder{
        ImageView iv_car;
        TextView title,price,date,address,time;
    }
}
